Function.prototype.xjhBind = function (thisArg, ...argArray) {
  var fn = this;
  // boundary judgement
  thisArg =
    thisArg !== null && thisArg !== undefined ? Object(thisArg) : window;

  function proxyFn(...args) {
    thisArg.fn = fn;
    var finalArgs = [...argArray, ...args];
    var result = thisArg.fn(...finalArgs);
    delete thisArg.fn;
    return result;
  }
  if (this.prototype) {
    // 如果你想要挂载默写原型的方法就是直接使用,赋值之前的原型
    proxyFn.prototype = Object.create(this.prototype);
  }
  return proxyFn;
};

function num(num1, num2) {
  let ret = num1 + num2;
  console.log(this, ret);
  return ret;
}

let obj = {
  name: "obj",
  age: 10,
};

// obj = '123'
// obj = 123
// obj = null

// let temp = num.bind(obj);
let temp = num.xjhBind(obj, 1);
let a = temp(3);
console.log(a);
